<?php
$title="修改商品信息";
$css="modifyproduct.css";
include_once 'common/AdminTop.php';
include_once 'authentic.php';
include_once '../Class/DB.php';
$db=new DB();
$classes=$db->get_bigClass_smallClass();
$str=json_encode($classes);
$pid=$_GET["id"];
$page=$_GET["page"];
$AProduct=$db->get_pid_product($pid);
$AProduct=$AProduct[0];

$ori_price=$_POST["ori_price"];
if(!isset($ori_price))
{
	$ori_price=$AProduct["ori_price"];
}
else if($ori_price=="")
{
	?>
	<script language="JavaScript">
	var page='<?php print_r($page);?>';
	var id='<?php print_r($pid);?>';
	alert("原价不能为空！");
	window.location.href="modifyproduct.php?page="+page+"&id="+id;
	</script>	
	<?php
	exit();
}

$act_price=$_POST["act_price"];
if(!isset($act_price))
{
	$act_price=$AProduct["act_price"];
}
else if($act_price=="")
{
	?>
	<script language="JavaScript">
	var page='<?php print_r($page);?>';
	var id='<?php print_r($pid);?>';
	alert("实价不能为空！");
	window.location.href="modifyproduct.php?page="+page+"&id="+id;
	</script>	
	<?php
	exit();
}


$count=$_POST["count"];
if(!isset($count))
{
	$count=$AProduct["count"];
}
else if($count=="")
{
	?>
	<script language="JavaScript">
	var page='<?php print_r($page);?>';
	var id='<?php print_r($pid);?>';
	alert("数量不能为空！");
	window.location.href="modifyproduct.php?page="+page+"&id="+id;
	</script>	
	<?php
	exit();
}

$onTime=$_POST["onTime"];
if(!isset($onTime))
{
	$onTime=$AProduct["onTime"];
}
else if($onTime=="")
{
	?>
	<script language="JavaScript">
	var page='<?php print_r($page);?>';
	var id='<?php print_r($pid);?>';
	alert("上架时间不能为空！");
	window.location.href="modifyproduct.php?page="+page+"&id="+id;
	</script>	
	<?php
	exit();
}

$b_name=$_POST["classify1"];
if(!isset($b_name))
{
	$s_class=$db->get_tid_types($AProduct["type"]);
	$b_class=$db->get_tid_types($s_class[0]["parent"]);
	$b_name=$b_class[0]["name"];
	//echo $b_class[0]["name"];
	//exit();
}
else if($b_name=="0")
{
	?>
	<script language="JavaScript">
	var page='<?php print_r($page);?>';
	var id='<?php print_r($pid);?>';
	alert("类型不能为所有类型！");
	window.location.href="modifyproduct.php?page="+page+"&id="+id;
	</script>	
	<?php
	exit();
}

$s_name=$_POST["classify2"];
if (!isset($s_name))
{
	$s_name=$s_class[0]["name"];
	//echo $s_name;
	//exit();
}
else if($s_name=="0")
{
	?>
	<script language="JavaScript">
	var page='<?php print_r($page);?>';
	var id='<?php print_r($pid);?>';
	alert("类型不能为所有类型！");
	window.location.href="modifyproduct.php?page="+page+"&id="+id;
	</script>	
	<?php
	exit();
}

$picurl=$_POST["picurl"];
if(!isset($picurl)||$picurl=="")
{
$picurl=$AProduct["pic_url"];
}
else {
	//echo $_SESSION["browser"];
	//echo "<br>";
	$picurl='../image/product_img/'.$picurl;
	//echo $picurl;
	//exit();
}

$meta=$_POST["meta"];
if(!isset($meta))
{
$meta=$AProduct["meta"];
}
else if($meta=="")
{
	?>
	<script language="JavaScript">
	var page='<?php print_r($page);?>';
	var id='<?php print_r($pid);?>';
	alert("关键字不能为空！");
	window.location.href="modifyproduct.php?page="+page+"&id="+id;
	</script>	
	<?php
	exit();
}

$introduction=$_POST["introduction"];
if(!isset($introduction))
{
$introduction=$AProduct["introduction"];
}else if($introduction=="")
{
	?>
	<script language="JavaScript">
	var page='<?php print_r($page);?>';
	var id='<?php print_r($pid);?>';
	alert("商品简介不能为空！");
	window.location.href="modifyproduct.php?page="+page+"&id="+id;
	</script>	
	<?php
	exit();
}
if(isset($_POST["classify2"]))//说明管理员按了保存按钮
{
	$s_tid=$db->get_name_tid($s_name, "s");
	$db->saveProduct($AProduct["pid"],$ori_price,$act_price,$count,$onTime,$s_tid,$picurl,$meta,$introduction);
	?>
	<script language="JavaScript">
	var page='<?php print_r($page);?>';
	window.location.href="productList.php?page="+page;
	</script>	
	<?php 	
	}
	?>
<script language="JavaScript">
var str='<?php print_r($str);?>';
//将PHP传来的字符串还原成数组
var classes = JSON.parse(str);
</script>
<script src="../js/modifyproduct.js" type="text/javascript"></script>
<div class="block_context" id="modify_block" align="center">
<p style="color:red">产品详细信息</p>
				<form action="modifyproduct.php?page=<?php echo $page;?>&id=<?php echo $AProduct["pid"];?>" method="post">
					<table>
						<tr>
							<th class="t1" >
							</th>
							<th class="t2">
							</th>	
						</tr>
						<tr>
							<td style="text-align: right;">
							<b>商品名称:</b>
							</td>
							<td style="text-align: left;"><?php echo $AProduct["p_name"];?></td>
						</tr>
						<tr>
							<td style="text-align: right;">
							<b>原价:</b>
							</td>
							<td style="text-align: left;"><label style="color:orange;">￥</label><input type="text" style="width:80px" name="ori_price" value="<?php echo number_format($AProduct["ori_price"],2,'.','');?>"></td>
						</tr>
						<tr>
							<td style="text-align: right;">
							<b>实价:</b>
							</td>
							<td style="text-align: left;"><label style="color:orange;">￥</label><input type="text" style="width:80px" name="act_price" value="<?php echo number_format($AProduct["act_price"],2,'.','');?>"></td>
						</tr>
						<tr>
							<td style="text-align:right;">
							<b>数量:</b>
							</td>
							<td style="padding-left:16px;text-align:left;"><input type="text" style="width:80px;" name="count"  value="<?php echo $AProduct["count"];?>"/></td>
						</tr>
						<tr>
							<td style="text-align: right;">
							<b>上架时间:</b>
							</td>
							<td style="padding-left:16px;text-align: left;">
								<input style="width:80px;" type="text" name="onTime" value="<?php echo $AProduct["onTime"]?>"/>
							</td>
						</tr>	
						<tr>
							<td style="text-align: right;">
							<b>商品类型:</b>
							</td>
							<td style="padding-left:16px;text-align: left;">
							
								<select name="classify1" onchange="on_select(this)" id="big">
								<option value="0">所有分类</option>
								<?php 
									$c_name=$db->get_parent_types(0);
									$i=0;
									while(isset($c_name[$i])){
	       								
	       							?>
	        						<option value="<?php echo $c_name[$i]["name"];?>"><?php echo $c_name[$i]["name"];?></option>
								<?php 	
									$i++;
									}
									?>
								</select>
								<select name="classify2" id="small">
			                     <option value="0">所有子分类</option>
								</select>
							</td>
						</tr>
						<tr>
						<td style="text-align: right;">
							<b>图片位置:</b>
						</td>
						<td style="padding-left:16px;text-align: left;">
						<input type="file" style="color:red;" name="picurl"  value="<?php echo $picurl;?>"/>		
						</td>
						</tr>
						<tr>
						<td style="text-align: right;">
							<b>关键字:</b>
						</td>
						<td style="padding-left:16px;text-align: left;">
						<input type="text"  name="meta"  value="<?php echo $meta;?>"/>		
						</td>
						</tr>
						<tr>
						<td style="text-align: right;">
							<b>商品简介:</b>
						</td>
						<td style="padding-left:16px;text-align: left;">
						<textarea name="introduction" style="width:250px;height:200px;font-size:12px;"><?php echo $introduction;?></textarea>		
						</td>
						</tr>
						</table>
						<p><input type="submit" value="保存修改" />
						<input type="button" value="返回列表" onclick="window.location.href='productList.php?page=<?php echo $page;?>'"/>
						</p>
				</form>
			</div>
<script language="JavaScript">
var bb='<?php print_r($b_name)?>';
var ss='<?php print_r($s_name)?>';
on_init(bb,ss);
</script>
<?php 
include_once 'common/AdminTail.php';
?>
